/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.help.service;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.service.BaseService;
import com.chlitina.store.modules.help.dao.SystemHelpOptionDao;
import com.chlitina.store.modules.help.entity.SystemHelpOption;

/**
 * 系统帮助页面实例Service
 * @author lvbo
 * @version 2014-03-31
 */
@Component
@Transactional(readOnly = true)
public class SystemHelpOptionService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(SystemHelpOptionService.class);
	
	@Autowired
	private SystemHelpOptionDao systemHelpOptionDao;
	
	public SystemHelpOption get(Long id) {
		return systemHelpOptionDao.findOne(id);
	}
	
	public Page<SystemHelpOption> find(Page<SystemHelpOption> page, SystemHelpOption systemHelpOption) {
		DetachedCriteria dc = systemHelpOptionDao.createDetachedCriteria();
		if (StringUtils.isNotEmpty(systemHelpOption.getSummary())){
			dc.add(Restrictions.like("summary", "%"+systemHelpOption.getSummary()+"%"));
		}
		dc.addOrder(Order.desc("id"));
		return systemHelpOptionDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(SystemHelpOption systemHelpOption) {
		systemHelpOptionDao.save(systemHelpOption);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		systemHelpOptionDao.delete(id);
	}
	
}
